package com.dyh.quickdemozwei.js;


import com.alibaba.fastjson.JSONObject;

/**
 * @Author: yhdong
 * @Date: 2021/9/16 16:26
 */


public class JsFieldValSetters {

    JsFieldValSetter simple = (jo,val,fromDef,toDef)-> jo.put(fromDef.getKey(),val);

    JsFieldValSetter complex = (jo,val,fromDef,toDef)->{
        String[] pathSp = toDef.getPath().split("/");

        JSONObject node = jo;
        for (String p : pathSp) {
            Object rawNode = node.get(p);
            if (rawNode==null)
                return;
            node = (JSONObject)rawNode;
        }
        if (node==null)
            return;
        node.put(fromDef.getKey(),val);
    };
}
